<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title>发帖</title>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
		<script type="text/javascript" src="../../js/index.js"></script>
		<script type="text/javascript">
        mui.plusReady(function() {
        	
        });
        function onSub() {
        	var user_id = plus.storage.getItem('user_id');  
        	var title = $('#title').val();
        	var content = $('#content').val();
        	var type = $('#type').val();
        	if(title == ""){
	            	alert('标题不能为空!');
	            	return ;
	            }
        	if(content == ""){
	            	alert('内容不能为空!');
	            	return ;
	            }
           mui.ajax({ //ajax请求
					url: getServerIp + 'AppNote/addNote',
					type: 'POST',
					data: {
						user_id: user_id,title:title,content:content,type:type
					}, //传参
					success: function(data, textStatus, jqXHR) {
						alert("发帖成功");
						mui.openWindow({
	                        url: '../../community.html', 
	                        id:'community'
                   		}); 
					}
					});
 
        }
        // 拍照
function getImage() {
	var cmr = plus.camera.getCamera();
	cmr.captureImage( function ( p ) {
		plus.io.resolveLocalFileSystemURL( p, function ( entry ) {
			document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+entry.toLocalURL()+"'>";
	        $("#picture").hide();
	        $(".mui-backdrop").hide();
	        
	
	//	createItem( entry );
		}, function ( e ) {
//		alert( "读取拍照文件错误："+e.message );
		} );
	}, function ( e ) {
//	alert( "失败："+e.message );
	});
}

function galleryImg() {
	var user_id = plus.storage.getItem('user_id');
	// 从相册中选择图片
    plus.gallery.pick( function(path){
    	//alert(path);
	mui.ajax({ //ajax请求
					url: getServerIp + 'AppUser/resetImage',
					contentType:"multipart/form-data",
					type: 'POST',
					data: {    
						files:path,id:user_id
					}, //传参
					success: function(data, textStatus, jqXHR) {
						
						alert(data.files);
					}
					});
    	//console.log(path);
    	document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+path+"'>";
	    $("#picture").hide();
	    $(".mui-backdrop").hide();
//  	outLine(path);
        //showImg( path );
        //createItem(path);
    }, function ( e ) {
    	outSet( "取消选择图片" );
    }, {filter:"image"} );
}
		</script>

		<link rel="stylesheet" href="../../css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-bar-nav~.mui-content {
				padding: 0;
			}
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
				padding: 10px 0;
                border-bottom: 1px solid #ddd;
			}
			.textarea_comment {
				margin-top: 45px;
			}
        </style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<button class="mui-action-back mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left">
				<span class="mui-icon mui-icon-left-nav" style="float: left;height: 40px;line-height: 40px;"></span>
				<img src="../../images/logo.png"  style=" height: 40px;"/>
			</button>
			<h1 class="mui-title">发帖子</h1>
			<a class="mui-icon mui-icon-right-nav" style="float: right;font-size: 18px;line-height: 30px;" onclick="onSub();">发送</a>
		</header>
		<form style="padding: 11px 15px;">
			<p style="margin-top: 45px;float: left;line-height: 45px;font-size: 16px;color: #000;">发帖到：</p>
			<select style="margin-top: 45px;float: right;width: 70%;" id="type">
				<option>体验说说</option>
				<option>学习交流</option>
				<option>成长日记</option>
				<option>意见反馈</option>
			</select>
		  <input style="margin-top: 0;" type="text" class="textarea_comment" placeholder="输入标题（最多24个字）"  id="title"/>
		  <div style="border: 1px solid #DDDDDD;background: #FFFFFF;">
		    <textarea rows="10 placeholder="输入内容" style="border: 0;" id="content"></textarea>
		    <div id="headImgDiv"></div>
		    <a href="#picture"><img id="pic" style="width: 20vw;margin-left: 2vw;" src="../../images/addimg.png"/></a>
		    <!--<div style="float: right;">
		    	<span class="mui-icon mui-icon-words"></span>
		    	<span id="count_text" style="color: red;">0</span>/500
		    	
		    	<span class="mui-icon mui-icon-images"></span>
		    	<span id="count_img" style="color: red;">0</span>/9
		    </div>-->
		  </div>
		</form>
		
		<div id="picture" class="mui-popover mui-popover-action mui-popover-bottom">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<a onclick="getImage();">拍照上传</a>
				</li>
				<li class="mui-table-view-cell">
					<a onclick="galleryImg()">选取现有的</a>
				</li>
			</ul>
			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<a href="#picture"><b>取消</b></a>
				</li>
			</ul>
		</div>
	</body>
</html>